Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

201
Vistas
What is the Java Equivalent of C# "Logical Call Context"

In .net, there is an "uber" thread-local-storage (TLS) which allows arbitrary TLS data to auto-magically "jump" from one thread to another. It is based on the CallContext class.

In other words, a logical request can spawn a hierarchy of new threads - and each of those threads will have access to the same TLS of the original thread. It is a very powerful feature, particularly for logging, authorization, multi-tenancy, or branding concerns.

What is the equivalent in Java?

Only in .net 4.5 has the "logical callcontext" gained a "copy on write" capability that allows threads to make private modifications to the logical callcontext. In other words, .net is still maturing this capability and providing greater stability.

If Java has an equivalent notion, how stable is it? What issues does it have?

Clarification

I already know that Java has a thread local storage (TLS) capability. That is not the question. I am asking if Java has an equivalent of the .net "logical call context" which is a much more powerful construct than simple TLS.

over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

Maybe InheritableThreadLocal is what you're looking for?

I'm not sure if it's exactly the same, but as far as I understand it meets this requirement:

a logical request can spawn a hierarchy of new threads - and each of those threads will have access to the same TLS of the original thread.

From the docs

This class extends ThreadLocal to provide inheritance of values from parent thread to child thread: when a child thread is created, the child receives initial values for all inheritable thread-local variables for which the parent has values. Normally the child's values will be identical to the parent's; however, the child's value can be made an arbitrary function of the parent's by overriding the childValue method in this class. Inheritable thread-local variables are used in preference to ordinary thread-local variables when the per-thread-attribute being maintained in the variable (e.g., User ID, Transaction ID) must be automatically transmitted to any child threads that are created.

I don't know about the "copy on write" capability you mentioned, but I guess you can override InheritableThreadLocal.childValue(T) to proxy the parent's value so that writes don't go through to the parent and modify the current thread's local storage

over 4 years ago · Santiago Trujillo Denunciar

0

I am not familiar with .net but from your Description the closest thing I could think of was a ThreadLocal.

However I found an article that you might find helpfull.

https://dzone.com/articles/thread-local-storage-java

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda